package com.hksj.Intelligentmanagement.utils;

import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.core.util.StrUtil;

public class UnicodeUtils {
    public static String toUnicode(String str){
        String res = "";
        if (StrUtil.isEmpty(str)){
            return str;
        }
        res = UnicodeUtil.toUnicode(str,false);
        res = StrUtil.trim(res.replaceAll("\\\\u","")).toUpperCase();

        return res;
    }

    public static String decode(String str){
        StringBuffer sb = new StringBuffer();
        if (StrUtil.isNotBlank(str)){
            str = str.replaceAll(" ","").trim();
            for (int i = 0; i <= str.length() - 4; i = i + 4) {
                sb.append("\\u").append(str.substring(i,i + 4));
            }
        }
        return UnicodeUtil.toString(sb.toString());
    }
}
